<?php

/**
 * 发送单条短信
 */

namespace App\Console\Commands;

use Illuminate\Console\Command;
use Log;
use Workerman\Worker;

class LongFile extends Command
{

    /**
     * The console command name.
     *
     * @var string
     */
    protected $name = 'LongFile';
    protected $signature = 'flow:LongFile {action} {--daemonize}';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'workerman httpserver';

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        global $argv;
        $action = $this->argument('action');

        $argv[0] = 'wk';
        $argv[1] = $action;
        $argv[2] = $this->option('daemonize') ? '-d' : '';

        $SmsWorker = new Worker('Text://0.0.0.0:22006');
        $SmsWorker->count = 4;
        $SmsWorker->name = 'LongFileWorker';
        $SmsWorker->onMessage = function ($connection, $LongFileData) {
            echo 5;
            Log::info('拆包操作-3333--' . $this->id);
        };

        /*  $BreakWorker =  new Worker('Text://0.0.0.0:33007');
        $BreakWorker->count = 12;
        $BreakWorker->name = 'BreakWorker';
        $BreakWorker->onMessage = function ($connection, $BreakData) {
            $dat = json_decode($BreakData,true);
            if(!isset($dat['id'])){
                Log::info($BreakData. 'Break Error 数据有误');
                return ;
            }
            $modelTasking = new WlktaskingRepository();
            $modelTasking->changeInfo($dat['id']);
            // 写入日志
            Log::info($BreakData. '拆包成功');
        };


        $SendBach = new Worker('Text://0.0.0.0:33008');
        $SendBach->count = 4;
        $SendBach->name = 'SendBach';
        $SendBach->onMessage = function ($connection, $BachData) {
            $tmp = json_decode($BachData, true);
            if(!isset($tmp['id'])){
                Log::info($BachData. 'BachData Error 数据有误');
                return ;
            }
            $modelTickets = new ApiRepository();
            $modelTickets->sendSmsMulti2($tmp['id']);
            // 写入日志
            Log::info($tmp['id'] . '发送成功');
        };*/


        Worker::runAll();
    }
}
